package com.ryx.controller;

import com.ryx.aop.annotation.MyLog;
import com.ryx.entity.SysRole;
import com.ryx.service.RoleService;
import com.ryx.utils.DataResult;
import com.ryx.vo.req.AddRoleReqVo;
import com.ryx.vo.req.RolePageReqVo;
import com.ryx.vo.req.RoleUpdateReqVo;
import com.ryx.vo.resp.PageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * @BelongsPackage: com.ryx.controller
 * @Author: 容永轩
 * @CreateTime: 2020-12-27
 * @Description:
 */
@RestController
@RequestMapping("/api")
@Api(tags = "Role Manager Interface")
public class RoleController {

    @Autowired
    private RoleService roleService;


    @PostMapping("/roles")
    @ApiOperation(value = "分页获取角色数据")
    @MyLog(title = "组织管理-角色管理",action = "分页获取角色数据接口")
    @RequiresPermissions("sys:role:list")
    public DataResult<PageVo<SysRole>> pageInfo(@RequestBody @Valid RolePageReqVo vo) {

        DataResult result = DataResult.success();

        result.setData(roleService.pageInfo(vo));

        return result;

    }

    @PostMapping("/role")
    @ApiOperation(value = "新增角色接口")
    @MyLog(title = "组织管理-角色管理",action = "新增角色接口")
    @RequiresPermissions("sys:role:add")
    public DataResult<SysRole> addRole(@RequestBody @Valid AddRoleReqVo vo) {
        DataResult result = DataResult.success();

        result.setData(roleService.addRole(vo));

        return result;
    }

    @GetMapping("/role/{id}")
    @ApiOperation(value = "获取角色详情接口")
    @MyLog(title = "组织管理-角色管理",action = "获取角色详情接口")
    @RequiresPermissions("sys:role:detail")
    public DataResult<SysRole> detailInfo(@PathVariable("id") String id){
        DataResult result=DataResult.success();
        result.setData(roleService.detailInfo(id));
        return result;
    }

    @PutMapping("/role")
    @ApiOperation(value = "更新角色信息接口")
    @MyLog(title = "组织管理-角色管理",action = "更新角色信息接口")
    @RequiresPermissions("sys:role:update")
    public DataResult updateRole(@RequestBody @Valid RoleUpdateReqVo vo){
        DataResult result=DataResult.success();
        roleService.updateRole(vo);
        return result;
    }

    @DeleteMapping("/role/{id}")
    @ApiOperation(value = "删除角色接口")
    @MyLog(title = "组织管理-角色管理",action = "删除角色接口")
    @RequiresPermissions("sys:role:delete")
    public DataResult deleteRole(@PathVariable("id") String roleId){
        roleService.deletedRole(roleId);

        return DataResult.success();
    }


}